﻿using IntelligentAgriculture.Contracts.Interface;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.LambweaninginfoCommand;
using MediatR;

namespace IntelligentAgriculture.WebAPI.Application.CommandHandler.LambweaninginfoCommandHandler
{
	/// <summary>
	/// 修改羔羊断奶
	/// </summary>
	/// <returns></returns>
	public class UpdateLambweaninginfoCommandHandler : IRequestHandler<UpdateLambweaninginfoCommand, Results<int>>
	{
		/// <summary>
		/// 接口
		/// </summary>
		private readonly ILambweaninginfoService _lambweaninginfoService;
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name="lambweaninginfoService"></param>

		public UpdateLambweaninginfoCommandHandler(ILambweaninginfoService lambweaninginfoService)
		{
			_lambweaninginfoService = lambweaninginfoService;
		}
		/// <summary>
		/// 修改羔羊断奶
		/// </summary>
		/// <returns></returns>
		public async Task<Results<int>> Handle(UpdateLambweaninginfoCommand request, CancellationToken cancellationToken)
		{
			var entity = new Lambweaninginfo()
			{
				LambWeaningId=request.LambWeaningId,
				WeaningAge = request.WeaningAge,
				WeaningDate = request.WeaningDate,
				WeaningWeight = request.WeaningWeight,
				CreateName = request.CreateName,
				CreateTime = request.CreateTime,
				CurrentBuilding = request.CurrentBuilding,
				CurrentField = request.CurrentField,
				EarTag = request.EarTag,
				IsDel = request.IsDel,
				MammalianNumber = request.MammalianNumber,
				Parity = request.Parity,
				Sex = request.Sex,
				ToBuildingManageId = request.ToBuildingManageId,
				ToColumnManagementId = request.ToColumnManagementId,
				UpdateName = request.UpdateName,
				UpdateTime = request.UpdateTime,
				UserId = request.UserId,
			};
			var result= await _lambweaninginfoService.UpdateLambweaninginfo(entity);
			return Results<int>.DataResult(result);
		}
	}
}
